• Projects
  • R Packages
  • Publications
  • Graduate Students
  • Links
  • Courses
    • Single-case regression analzes
  • Private blog

On this page

  • Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrast.
  • Example dataset
  • Descriptives
  • Contrasts

What’s that all about the contrasts

methods
stats
contrasts
Author

Jürgen Wilbert

Published

May 17, 2023

Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrast.

Example dataset

Create a random dataset with criteria y, predictors x1 and x2 and gender.

All variables are correlated.

n <- 10000
gender <- rep(0:1, each = n/2)
y <- sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x1 <- y + sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x2 <- y + x1 + sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)

dat <- data.frame(y = y, x1 = x1, x2 = x2, gender = gender)

Descriptives

psych::corr.test(dat)
Call:psych::corr.test(x = dat)
Correlation matrix 
          y   x1   x2 gender
y      1.00 0.80 0.87   0.55
x1     0.80 1.00 0.93   0.67
x2     0.87 0.93 1.00   0.73
gender 0.55 0.67 0.73   1.00
Sample Size 
[1] 10000
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
       y x1 x2 gender
y      0  0  0      0
x1     0  0  0      0
x2     0  0  0      0
gender 0  0  0      0

 To see confidence intervals of the correlations, print with the short=FALSE option
psych::describe(dat)
vars n mean sd median trimmed mad min max range skew kurtosis se
y 1 10000 7.5041 4.597858 7.0 7.28475 4.4478 0 20 20 0.3712705 -0.4346202 0.0459786
x1 2 10000 14.9931 7.376659 14.0 14.68075 7.4130 0 39 39 0.3635167 -0.4501117 0.0737666
x2 3 10000 30.0624 13.784706 29.0 29.49638 14.8260 0 76 76 0.3493704 -0.5603446 0.1378471
gender 4 10000 0.5000 0.500025 0.5 0.50000 0.7413 0 1 1 0.0000000 -2.0002000 0.0050003

Contrasts

The left part of the table is with gender as treatment contrast (0 vs. 1) and the right part with gender as effect contrast (-1 vs. 1)

# Gender has values 0 vs. 1 (treatment contrast)
fit1 <- lm(y ~ gender * x1 * x2, data = dat)

# Gender hast -1 vs. 1 (effect contrast)
dat$gender <- car::recode(dat$gender, "0 = -1; 1 = 1")

fit2 <- lm(y ~ gender * x1 * x2, data = dat)

sjPlot::tab_model(fit1, fit2, show.std = TRUE, show.ci = FALSE, col.order = c("est", "se", "std.est", "p"), digits = 4)
  y y
Predictors Estimates std. Beta p Estimates std. Beta p
(Intercept) -1.6773 0.0029 <0.001 -2.4592 0.0029 <0.001
gender -1.5638 -0.1739 <0.001 -0.7819 -0.1739 <0.001
x1 0.0011 -0.0173 0.960 -0.0094 -0.0173 0.507
x2 0.3324 1.0089 <0.001 0.3373 1.0089 <0.001
gender × x1 -0.0209 -0.0176 0.458 -0.0105 -0.0176 0.458
gender × x2 0.0098 0.0139 0.511 0.0049 0.0139 0.511
x1 × x2 -0.0000 -0.0011 0.971 -0.0000 -0.0011 0.915
(gender × x1) × x2 -0.0000 -0.0004 0.968 -0.0000 -0.0004 0.968
Observations 10000 10000
R2 / R2 adjusted 0.763 / 0.763 0.763 / 0.763
 
Copyright 2023, Jürgen Wilbert